package com.example.tianling.admin.service.Impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tianling.admin.service.UserDataService;
import com.example.tianling.dao.UserMapper;
import com.example.tianling.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserDataServiceImpl
        extends ServiceImpl<UserMapper, UserEntity>
        implements UserDataService {
    @Autowired
    private UserMapper userMapper;
//加载刷新论坛页面
   public List<Map<String, Object>> sumUser(){
       // 使用QueryWrapper来构建查询条件
       QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();

       queryWrapper.select("type", "count(type) as count")
               .groupBy("type");
       return userMapper.selectMaps(queryWrapper);
   }
   public List<UserEntity> findUserByName(String keyword){
       QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
       queryWrapper.like("user_name",keyword);
       // 无条件查询，即查询全部记录数
       return userMapper.selectList(queryWrapper);
   }
}
